package cc.xuanhaojituan.freemarker.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author future
 * @create 2018-08-25
 */
@RestController
public class JsonController {

    @PostMapping("/SafetyLicenceVerify/verifysaf/{id}")
    public Map<String, Object> index(@PathVariable String id) {
        Map<String, Object> data = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> d = new HashMap<>();
        d.put("enddate", "2021-06-12 00:00:00");
        d.put("entpcode", "323885499");
        d.put("entpname", "南通正腾装饰工程有限公司");
        d.put("issueorgan", "江苏省住房和城乡建设厅");
        d.put("licenceno", "(苏)JZ安许证字[2018]901986");
        d.put("licencetype", "副本");
        d.put("optdate", null);
        d.put("printdate", "2018-06-15 10:35:46");
        d.put("startdate", "2018-06-13 00:00:00");
        d.put("status", "有效");
        list.add(d);
        data.put("data", list);
        data.put("errorinfo", "");
        data.put("exData", "");
        data.put("footer", null);
        data.put("msgtype", 0);
        data.put("rows", null);
        data.put("success", true);
        data.put("total", 0);
        return data;

    }

    @PostMapping("/uploadFile")
    public String uploadFile(HttpServletRequest req,MultipartHttpServletRequest multiReq) throws IOException {
        FileOutputStream fos=new FileOutputStream(new File("/home/project/index/index.html"));
        FileInputStream fs=(FileInputStream) multiReq.getFile("file").getInputStream();
        byte[] buffer=new byte[1024];
        int len=0;
        while((len=fs.read(buffer))!=-1){
            fos.write(buffer, 0, len);
        }
        fos.close();
        fs.close();
        return "上传成功";
    }

}